TGML Script Element: <Script>
Script defines a script block that belongs to the immediate parent element.
Specifying an event attribute on the Script element makes the parent element the target for the specified event. For example, if OnMouseClick and the function name "click" are specified, the click function is executed when the user clicks the parent element (assuming that the element is a visible graphical element).
If the parent element of Script is a container element, such as Component, the mouse event is sent when any of the contained graphical elements are hit. The hit element is the target, while the parent element, which handles the event, is the current target.
The functions are always defined with an in parameter. The parameter is a reference to the event object that can be used to get event specific information and to access the DOM, starting with getTarget or getCurrentTarget.
Each Script element (script block) creates a JavaScript context. Function calls between script blocks (contexts) are not supported, that is, no support for global script functions.
The script functions are stored in the CDATA section of the Script element. The CDATA section is accessible through the Content attribute.
Attribute | Type | Description |
---|---|---|
Content |
String |
The script. |
Event Attribute | Event Type | Target | Description |
---|---|---|---|
OnDocumentLoad |
DocumentLoadEvent |
Any element |
The TGML document is uploaded (opened). |
OnMouseClick |
MouseClickEvent |
Painted element |
A mouse button is clicked over an element. |
OnMouseDown |
MouseDownEvent |
Painted element |
A mouse button is pressed over an element. |
OnMouseUp |
MouseUpEvent |
Painted element |
A mouse button is released over an element. |
OnMouseOver |
MouseOverEvent |
Painted element |
The pointer is moved onto an element. |
OnMouseMove |
MouseMoveEvent |
Bind element |
The pointer is moved while it is over an element. |
OnMouseOut |
MouseOutEvent |
Painted element |
The pointer is moved away from an element. |
OnSignalChange |
SignalChangeEvent |
Painted element |
The value of the bound signal has been changed. |
Example:
<TGML>
<Rectangle Name="MyRect" Left="50" Top="50" Width="100" Height="100" Fil1="#FFFFFF" Stroke="#000000" >
<Script OnMouseClick="click"><! [CDATA [
function click (evt)
{
var element = evt.getTarget();
var name = element.getAttribute("Name");
var mouseX = evt.getClientX();
var mouseY = evt.getClientY();
var message = "You hit " + name + " at " + mouseX + "," + mouseY;
alert(message);
}
] ]></Script>
</Rectangle>
</TGML>
Example on screen: